package PTA_JAVA.Exception6.demo4;

import java.util.Scanner;

public class Main {
    public static void main(String[] args)  {
        Scanner sc=new Scanner(System.in);
        String s;
        while(!"other".equals(s=sc.nextLine())){
            if("new".equals(s)){
                String[] str = sc.nextLine().split(" ");
                if(str.length==2){
                    Student student = new Student();
                    try {
                        student.setName(str[0]);
                        student.addScore(Integer.parseInt(str[1]));
                        System.out.println(student);
                    } catch (Exception e) {
                        System.out.println(e);
                    }
                }else{
                    System.out.println("java.util.NoSuchElementException");
                }
            }
            String[] arr = s.split(" ");
        }
        sc.close();
        System.out.println("scanner closed");
    }
}

class IllegalNameException extends Exception {

    public IllegalNameException(String e) {
        super(e);
    }
}
class IllegalScoreException extends Exception {

    public IllegalScoreException(String e) {
        super(e);
    }
}
class Student{
    private String name;
    private int score;

    @Override
    public String toString() {
        return "Student [" +
                "name=" + name +
                ", score=" + score +
                "]";
    }
    public String getName() {
        return name;
    }

    public void setName(String name) throws IllegalNameException {
        if(name.substring(0,1).matches("[0-9]")){
            throw new IllegalNameException("the first char of name must not be digit, name="+name);
        }else{
            this.name = name;   //如果姓名首字母为数字则抛出IllegalNameException
        }
    }

    public int addScore(int score) throws IllegalScoreException {
        if(score<0 || score>100){
            throw new IllegalScoreException("score out of range, score="+score);
        }else{
            this.score=score;
        }
        return score;
    }  //如果加分后分数<0 或>100，则抛出IllegalScoreException，加分不成功。



    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }
}